package cn.dust.design.pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: dust
 * @Date: 2019/11/26 22:31
 */
public class CourceCatalog extends CatalogComponent{

    private List<CatalogComponent>items=new ArrayList<CatalogComponent>();
    private String name;
    private Integer level;

    public CourceCatalog(String name,Integer level) {
        this.name = name;
        this.level=level;
    }


    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public String getName(CatalogComponent catalogComponent) {
        return this.name;
    }

    @Override
    public void delete(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public void print() {
        System.out.println(this.name);
        for(CatalogComponent catalogComponent:items){
            if(this.level!=null){
                for(int i=0;i<this.level;i++){
                    System.out.print(" ");
                }
            }
            catalogComponent.print();
        }
    }
}
